package com.ruoyi.pingjiao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pingjiao.domain.PaperItemCategory;
import com.ruoyi.pingjiao.service.IPaperItemCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评教问卷类管理Controller
 * 
 * @author ruoyi
 * @date 2022-10-22
 */
@RestController
@RequestMapping("/pingjiao/category")
public class PaperItemCategoryController extends BaseController
{
    @Autowired
    private IPaperItemCategoryService paperItemCategoryService;

    /**
     * 查询评教问卷类管理列表
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaperItemCategory paperItemCategory)
    {
        startPage();
        List<PaperItemCategory> list = paperItemCategoryService.selectPaperItemCategoryList(paperItemCategory);
        return getDataTable(list);
    }

    /**
     * 导出评教问卷类管理列表
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:category:export')")
    @Log(title = "评教问卷类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperItemCategory paperItemCategory)
    {
        List<PaperItemCategory> list = paperItemCategoryService.selectPaperItemCategoryList(paperItemCategory);
        ExcelUtil<PaperItemCategory> util = new ExcelUtil<PaperItemCategory>(PaperItemCategory.class);
        util.exportExcel(response, list, "评教问卷类管理数据");
    }

    /**
     * 获取评教问卷类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:category:query')")
    @GetMapping(value = "/{paperItemCategoryId}")
    public AjaxResult getInfo(@PathVariable("paperItemCategoryId") Long paperItemCategoryId)
    {
        return AjaxResult.success(paperItemCategoryService.selectPaperItemCategoryByPaperItemCategoryId(paperItemCategoryId));
    }

    /**
     * 新增评教问卷类管理
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:category:add')")
    @Log(title = "评教问卷类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperItemCategory paperItemCategory)
    {
        return AjaxResult.success(paperItemCategoryService.insertPaperItemCategory(paperItemCategory));
    }

    /**
     * 修改评教问卷类管理
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:category:edit')")
    @Log(title = "评教问卷类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperItemCategory paperItemCategory)
    {
        return toAjax(paperItemCategoryService.updatePaperItemCategory(paperItemCategory));
    }

    /**
     * 删除评教问卷类管理
     */
    @PreAuthorize("@ss.hasPermi('pingjiao:category:remove')")
    @Log(title = "评教问卷类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paperItemCategoryIds}")
    public AjaxResult remove(@PathVariable Long[] paperItemCategoryIds)
    {
        return toAjax(paperItemCategoryService.deletePaperItemCategoryByPaperItemCategoryIds(paperItemCategoryIds));
    }

    /**
     * 通过问卷项目类别名称查询问卷题
     * @param paperItemCategoryName
     * @return
     */
    @GetMapping("/getItem/{paperItemCategoryName}")
    public AjaxResult getPaperItemCategoryName(@PathVariable  String paperItemCategoryName){
        return AjaxResult.success(paperItemCategoryService.selectPaperItemByPaperItemCategoryName(paperItemCategoryName));
    }
}
